package com.ziyia.a2_10_all;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.PopupMenu;
import android.widget.Toast;
import android.widget.Toolbar;

public class MyPopupMenu extends AppCompatActivity {

    private Button button;
    private PopupMenu popupMenu;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_popup_menu);



        button = findViewById(R.id.btn);
        popupMenu = new PopupMenu(this, button);

        getMenuInflater().inflate(R.menu.menu3, popupMenu.getMenu());

        popupMenu.setOnMenuItemClickListener((item) -> {
            Toast.makeText(MyPopupMenu.this, item.getTitle(), Toast.LENGTH_SHORT).show();
            return true;
        });
    }

    public void show(View view) {
        popupMenu.show();
    }
}